package tools

import (
	"github.com/shopspring/decimal"
	"strconv"
)

func StringToFloat(s string) (float64, error) {
	f, err := strconv.ParseFloat(s, 64)
	if err != nil {
		return 0, err
	}
	return f, nil
}

func GetDecimalValue(jsonData map[string]interface{}, field string) *decimal.Decimal {
	value, _ := jsonData[field]

	if value != nil {
		decimalValue := decimal.NewFromFloat(value.(float64))
		return &decimalValue
	} else {
		return nil
	}
}
